package services

import play.api.libs.json._
import play.api.libs.functional.syntax._

//  {"code":0,"msg":"","count":l,"data":data[s:e]}
case class TestJson(code:Long,msg:String,count:Long,data:Seq[TestData])
case class TestData(id:Int,username:String,sex:String,city:String,sign:String,experience:Int,logins:Int,wealth:Long,classify:String,score:Int)
object TestJson{
  implicit val testDataWrites: Writes[TestData] = Json.format[TestData]
  implicit val testJsonWrites: Writes[TestJson] =(
    (JsPath \ "code").write[Long] and
      (JsPath \ "msg").write[String] and
      (JsPath \ "count").write[Long] and
      (JsPath \ "data").write[Seq[TestData]]
    )(unlift(TestJson.unapply))
  var list = Seq(
    TestData(10000,"user-0","女","城市-0","签名-0",255,24,82830700,"作家",57),
    TestData(10001,"user-1","男","城市-1","签名-1",884,58,64928690,"词人",27),
    TestData(10002,"user-2","女","城市-2","签名-2",650,77,6298078,"酱油",31),
    TestData(10003,"user-3","女","城市-3","签名-3",362,157,37117017,"诗人",68),
    TestData(10004,"user-4","男","城市-4","签名-4",807,51,76263262,"作家",6),
    TestData(10005,"user-5","女","城市-5","签名-5",173,68,60344147,"作家",87),
    TestData(10006,"user-6","女","城市-6","签名-6",982,37,57768166,"作家",34),
    TestData(10007,"user-7","男","城市-7","签名-7",727,150,82030578,"作家",28),
    TestData(10008,"user-8","男","城市-8","签名-8",951,133,16503371,"词人",14),
    TestData(10009,"user-9","女","城市-9","签名-9",484,25,86801934,"词人",75),
    TestData(10010,"user-10","女","城市-10","签名-10",1016,182,71294671,"诗人",34),
    TestData(10011,"user-11","女","城市-11","签名-11",492,107,8062783,"诗人",6),
    TestData(10012,"user-12","女","城市-12","签名-12",106,176,42622704,"词人",54),
    TestData(10013,"user-13","男","城市-13","签名-13",1047,94,59508583,"诗人",63),
    TestData(10014,"user-14","男","城市-14","签名-14",873,116,72549912,"词人",8),
    TestData(10015,"user-15","女","城市-15","签名-15",1068,27,52737025,"作家",28),
    TestData(10016,"user-16","女","城市-16","签名-16",862,168,37069775,"酱油",86),
    TestData(10017,"user-17","女","城市-17","签名-17",1060,187,66099525,"作家",69),
    TestData(10018,"user-18","女","城市-18","签名-18",866,88,81722326,"词人",74),
    TestData(10019,"user-19","女","城市-19","签名-19",682,106,68647362,"词人",51),
    TestData(10020,"user-20","男","城市-20","签名-20",770,24,92420248,"诗人",87),
    TestData(10021,"user-21","男","城市-21","签名-21",184,131,71566045,"词人",99),
    TestData(10022,"user-22","男","城市-22","签名-22",739,152,60907929,"作家",18),
    TestData(10023,"user-23","女","城市-23","签名-23",127,82,14765943,"作家",30),
    TestData(10024,"user-24","女","城市-24","签名-24",212,133,59011052,"词人",76),
    TestData(10025,"user-25","女","城市-25","签名-25",938,182,91183097,"作家",69),
    TestData(10026,"user-26","男","城市-26","签名-26",978,7,48008413,"作家",65),
    TestData(10027,"user-27","女","城市-27","签名-27",371,44,64419691,"诗人",60),
    TestData(10028,"user-28","女","城市-28","签名-28",977,21,75935022,"作家",37),
    TestData(10029,"user-29","男","城市-29","签名-29",647,107,97450636,"酱油",27),
    TestData(10030,"user-30","女","城市-30","签名-30",647,107,97450636,"酱油",27),
    TestData(10031,"user-31","女","城市-31","签名-31",648,108,97450637,"酱油",28),
    TestData(10032,"user-32","男","城市-32","签名-32",649,109,97450638,"酱油",29),
    TestData(10033,"user-33","女","城市-33","签名-33",650,110,97450639,"酱油",30),
    TestData(10034,"user-34","女","城市-34","签名-34",651,111,97450640,"酱油",31),
    TestData(10035,"user-35","男","城市-35","签名-35",652,112,97450641,"酱油",32),
    TestData(10036,"user-36","男","城市-36","签名-36",653,113,97450642,"酱油",33),
    TestData(10037,"user-37","女","城市-37","签名-37",654,114,97450643,"酱油",34),
    TestData(10038,"user-38","女","城市-38","签名-38",655,115,97450644,"酱油",35),
    TestData(10039,"user-39","女","城市-39","签名-39",656,116,97450645,"酱油",36),
    TestData(10040,"user-40","女","城市-40","签名-40",657,117,97450646,"酱油",37),
    TestData(10041,"user-41","男","城市-41","签名-41",658,118,97450647,"酱油",38),
    TestData(10042,"user-42","男","城市-42","签名-42",659,119,97450648,"酱油",39),
    TestData(10043,"user-43","女","城市-43","签名-43",660,120,97450649,"酱油",40),
    TestData(10044,"user-44","女","城市-44","签名-44",661,121,97450650,"酱油",41),
    TestData(10045,"user-45","女","城市-45","签名-45",662,122,97450651,"酱油",42),
    TestData(10046,"user-46","女","城市-46","签名-46",663,123,97450652,"酱油",43),
    TestData(10047,"user-47","女","城市-47","签名-47",664,124,97450653,"酱油",44),
    TestData(10048,"user-48","男","城市-48","签名-48",665,125,97450654,"酱油",45),
    TestData(10049,"user-49","男","城市-49","签名-49",666,126,97450655,"酱油",46),
    TestData(10050,"user-50","男","城市-50","签名-50",667,127,97450656,"酱油",47),
    TestData(10051,"user-51","女","城市-51","签名-51",668,128,97450657,"酱油",48),
    TestData(10052,"user-52","女","城市-52","签名-52",669,129,97450658,"酱油",49)
  )

  def testJson(page:Int=0,limit:Int=10,dataList:Seq[TestData]=list) = {
    val count = dataList.length
    val msg =""
    val data = dataList.take(page*limit).takeRight(limit)
    val dat = TestJson(code=0,msg,count,data)
    Json.toJson(dat)
  }
}
